package cn.jiadakeji.parent.controller;

import cn.jiadakeji.parent.common.core.controller.BaseController;
import cn.jiadakeji.parent.common.core.domain.AjaxResult;
import cn.jiadakeji.parent.common.page.TableDataInfo;
import cn.jiadakeji.parent.domain.Student;
import cn.jiadakeji.parent.dto.StudentDTO;
import cn.jiadakeji.parent.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author heyanfeng
 * @create 2022-03-09 15:18
 */
@Api(value = "学生信息", tags = {"学生信息接口"})
@RestController
@RequestMapping("/student")
public class StudentController extends BaseController {
    @Autowired
    private StudentService studentService;

    @ApiOperation("按照学籍号查找学生信息")
    @GetMapping("/WithNumber/{number}")
    public AjaxResult getStudentWithNumber(
            @ApiParam("学籍号")
            @PathVariable("number") String number) {
        StudentDTO studentDTO = studentService.getStudentWithNumber(number);
        return studentDTO != null ? AjaxResult.success(studentDTO)
                : AjaxResult.error("没有找到相关人员信息");

    }


    @ApiOperation("通过ID查找学生信息")
    @GetMapping("/WithId/{studentId}")
    public AjaxResult getStudentById(
            @ApiParam("学生ID")
            @PathVariable("studentId") String studentId) {
        StudentDTO studentDTO = studentService.getStudentById(studentId);
        return studentDTO != null ? AjaxResult.success(studentDTO)
                : AjaxResult.error("当前学生不存在");
    }

    @ApiOperation("通过班级ID查找学生")
    @GetMapping("/withClassId/{classId}")
    public AjaxResult getStudentByClassId(@PathVariable("classId") String classId) {
        List<Student> studentList = studentService.getStudentByClassId(classId);
        return AjaxResult.success(studentList);
    }

    @ApiOperation("通过年级班级查找学生信息")
    @GetMapping("/WithGrade/{schoolId}/{classId}")
    public TableDataInfo getStudentWithGrade(
            @ApiParam("学校ID")
            @PathVariable("schoolId") String schoolId,
            @ApiParam("班级ID")
            @PathVariable("classId") String classId) {
        startPage();
        List<StudentDTO> studentDTOList = studentService.getStudentWithGrade(schoolId, classId);
        return getDataTable(studentDTOList);
    }

}
